package api

import (
	"api/config"
	"api/internal/api/response"
	"api/internal/handler"
	"common/consulinit"
	"flag"
	"github.com/gin-gonic/gin"
	"strconv"
	pb "test_question_srv/proto"
)

var (
	questionAddress = config.ServerConfigs.QuestionSrv.Host + ":" + strconv.Itoa(config.ServerConfigs.QuestionSrv.Port)
	questionServer  = flag.String(config.ServerConfigs.QuestionSrv.Name, questionAddress, "The server address")
	questionSrv     = handler.NewClient().QuestionServer(questionServer)
)

func RegisterQuestionService() {
	consulinit.NewConsulClient("117.27.231.112", 8500).RegisterConsul(config.ServerConfigs.QuestionSrv.Name, []string{"server"},
		config.ServerConfigs.QuestionSrv.Port, config.ServerConfigs.QuestionSrv.Host)
}

func List(c *gin.Context) {
	RegisterQuestionService()
	list, err := questionSrv.List(c, &pb.ListRequest{})
	if err != nil {
		response.Response(c, 400, err.Error(), nil)
		return
	}
	response.Response(c, 200, "无限极分类展示成功", list)
}
